var buildTree = function(inorder, postorder) {
if (!inorder.length || !postorder.length) {
return null
}
let rootVal = postorder[postorder.length - 1]
let root = new TreeNode(rootVal)
let k = inorder.indexOf(rootVal)
root.left = buildTree(inorder.slice(0, k), postorder.slice(0, k))
root.right = buildTree(inorder.slice(k+1), postorder.slice(k, postorder.length - 1))
return root
};
def build_tree(inorder, postorder)
length=postorder.length
if length==0
return nil
end
root=TreeNode.new(postorder[length-1])
mid=0
while inorder[mid]!=postorder[length-1]
mid+=1
end
root.left=build_tree(inorder[0...mid],postorder[0...mid])
root.right=build_tree(inorder[mid+1...inorder.length],postorder[mid...length-1])
return root
end